<?php
/**
 * Created by PhpStorm.
 * User: this
 * Date: 2018/12/28
 * Time: 16:47
 */
namespace app\index\controller;
use think\Controller;
use think\Db;

class Base extends Controller{
    protected $config;
    protected $m;
    /**
     * Base constructor.
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    function __construct(){
        //继承运行父类模板
        parent::__construct();
        # code...
        //获取网站信息
        $this->getConfig();
        //获取导航
        $this->getMenu();
    }

    /**
     * 获取网站基本信息
     */
    private function getConfig(){
        $info = Db::name('setting')->field('*')->cache(true,5)->select();
        $this->config = $info;
    }

    /**
     * 获取导航
     */
    private function getMenu(){
        $this->m = Db::name('menu')->field('menu_name,menu_url,menu_id,menu_desc')->where(array('menu_status'=>1))->cache(true)->order('menu_id asc')->select();
    }

    public function getVal($code){
        $info = $this->config;
        $val = '';
        foreach ($info as $v){
            if($v['setting_cod'] == $code){
                $val = $v['setting_value'];
            }
        }
        return $val;
    }
}